home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1989 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  123 lines

  1. Path: sn.no!usenet
  2. From: elvemo@sn.no (Rune Elvemo)
  3. Newsgroups: comp.lang.c
  4. Subject: Problem with program
  5. Date: Thu, 18 Jan 1996 07:12:33 GMT
  6. Organization: SN Internett
  7. Message-ID: <4dkr5u$ro7@hasle.sn.no>
  8. NNTP-Posting-Host: af-04.kvadraturen.vgs.no
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Anyone who can figure out what is wrong with this program?
  12.  
  13. I tried to compile it, but my compiler wouldn't.....
  14.  
  15. Ex: It said that the prototype needed a semicolon, but it
  16. don't.........
  17.  
  18.  
  19.  
  20. /* Loadfile.c - loads a txt file, and shows it 
  21. **
  22. **
  23. */
  24.  
  25. #include <stdio.h>
  26.  
  27. struct Text
  28. {
  29. char *str;
  30. struct Text *next;
  31. }
  32.  
  33.  
  34. enum BOOL { TRUE, FALSE };
  35.  
  36. /* prototype */
  37. void PText(struct Text *);
  38.  
  39.  
  40. main(int argc, char *argv[])
  41. {
  42. BOOL done = FALSE;
  43. FILE *txtfile;
  44. struct Text *first, *tst;
  45.  
  46. if (argc >1)
  47.      {
  48.      if (txtfile = fopen(argv[1], "r"))
  49.           {
  50.           if(first = calloc(1, sizeof(struct Text)))
  51.                {
  52.                tst = first;
  53.                if (fgetc(txtfile) != -1)
  54.                     {
  55.                     while (!done)
  56.                          {
  57.                          if (tst->str = calloc(256, sizeof(char)))
  58.                               {
  59.                               do
  60.                                    {
  61.                                    *tst->str = fgetc(txtfile);
  62.                                    tst->str++;
  63.                                    *tst->str = 0;
  64. /* check if the last char was LineFeed or EOF  */
  65.  
  66.                                    } while ((*(tst->str - 1) != -1) &&
  67. (*(tst->str) != 10));
  68.                                    
  69.                               if (*tst->str == -1)
  70.                                    done = TRUE;
  71.                               else
  72.                                    {
  73.                                    if (tst->next = calloc(1,
  74. sizeof(struct Text)))
  75.                                         {
  76.                                         tst = tst->next;
  77.  
  78.                                         }
  79.                                    else
  80.                                         {
  81.                                         done = TRUE;
  82.                                         printf("\n**!!Not enough
  83. memory!!**\n");
  84.                                         }
  85.                                    }
  86.                               }
  87.                          }
  88.                     tst->next = calloc(1, sizeof(struct Text));
  89.                     
  90.                     
  91.                     PText(first);
  92.                     }
  93.                }
  94.           else
  95.                printf("\n**!!Not enough memory!!**\n");
  96.           }
  97.      }
  98. }
  99.      
  100. /* Print the text that we have got */
  101. void PText(struct Text *txt)
  102. {
  103. BOOL done = FALSE;
  104. struct Text *jump;
  105.  
  106. jump = txt;
  107.  
  108. while(!done)
  109.      {
  110.      printf("%s", jump->str);
  111.      
  112.      while (*txt->next != 0)
  113.           {
  114.           jump = jump->next;
  115.           
  116.           printf("%s\n", jump);
  117.           }
  118.      }
  119. }
  120. Rune Elvemo
  121. elvemo@oslonett.no
  122.  
  123.